/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc67;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc67Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc67QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc67Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-28
**/
@Service
@RequiredArgsConstructor
public class TransferIc67ServiceImpl extends ServiceImpl<TransferIc67Mapper, TransferIc67> implements TransferIc67Service {

    private final TransferIc67Mapper transferIc67Mapper;

    @Override
    public PageResult<TransferIc67> queryAll(TransferIc67QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc67Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc67> queryAll(TransferIc67QueryCriteria criteria){
        return transferIc67Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc67 resources) {
        transferIc67Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc67 resources) {
        TransferIc67 transferIc67 = getById(resources.getAaz702());
        transferIc67.copy(resources);
        transferIc67Mapper.updateById(transferIc67);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc67Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc67> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc67 transferIc67 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc67.getAaz341());
            map.put("转出地人员编号", transferIc67.getAac319());
            map.put("人员编号", transferIc67.getAac001());
            map.put("转出地行政区划代码", transferIc67.getAab301());
            map.put("参保地行政区划代码", transferIc67.getAab299());
            map.put("参保地名称", transferIc67.getAab300());
            map.put("年度", transferIc67.getAae001());
            map.put("缴费起始时间", transferIc67.getAae041());
            map.put("缴费终止时间", transferIc67.getAae042());
            map.put("月缴费基数", transferIc67.getAae180());
            map.put("月数", transferIc67.getAae202());
            map.put("个人缴费比例", transferIc67.getAaa041());
            map.put("单位缴费比例", transferIc67.getAaa042());
            map.put("单位缴费划入个人账户比例", transferIc67.getAaa043());
            map.put("当年记账金额", transferIc67.getAae381());
            map.put("当年记账金额中的个人缴费部分", transferIc67.getAae264());
            map.put("当年记账利息", transferIc67.getAae269());
            map.put("当年记账利息中的个人缴费部分", transferIc67.getAae265());
            map.put("至本年末账户累计储存额中的个人缴费部分", transferIc67.getAae273());
            map.put("至本年末账户累计储存额", transferIc67.getAae382());
            map.put("机关养老关系转移接续信息表ID", transferIc67.getAaz701());
            map.put("转移数据来源", transferIc67.getAac306());
            map.put("人员参保关系ID", transferIc67.getAaz159());
            map.put("历年缴费流水号", transferIc67.getAaz751());
            map.put("备注", transferIc67.getAae013());
            map.put("经办人", transferIc67.getAae011());
            map.put("经办时间", transferIc67.getAae036());
            map.put("经办机构", transferIc67.getAab359());
            map.put("业务日志ID", transferIc67.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
